package com.shxzz.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shxzz.shortlink.project.common.convention.result.Result;
import com.shxzz.shortlink.project.common.convention.result.Results;
import com.shxzz.shortlink.project.dto.req.RecycleBinPageReqDTO;
import com.shxzz.shortlink.project.dto.req.RecycleBinRemoveReqDTO;
import com.shxzz.shortlink.project.dto.req.RecycleBinRestoreReqDTO;
import com.shxzz.shortlink.project.dto.req.RecycleBinSaveReqDTO;
import com.shxzz.shortlink.project.dto.resp.RecycleBinLinkPageRespDTO;
import com.shxzz.shortlink.project.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shxzz
 * @create 2023-12-25-19:20
 * @description 回收站管理控制层
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;

    /**
     * 移动链接到回收站
     * @param requireParam 移动链接到回收站请求参数
     */
    @PostMapping("/api/short-link/v1/recycle-bin/save")
    public Result<Void> moveLinkToRecycleBin(@RequestBody RecycleBinSaveReqDTO requireParam){
        recycleBinService.moveToRecycleBin(requireParam);
        return Results.success();
    }

    /**
     * 分页查询回收站链接
     * @param requireParam 分页查询参数
     * @return 分页查询结果
     */
    @GetMapping("/api/short-link/v1/recycle-bin/page")
    public Result<IPage<RecycleBinLinkPageRespDTO>> selectPageRecycleBinLink(RecycleBinPageReqDTO requireParam){
        return Results.success(recycleBinService.selectPageRecycleBin(requireParam));
    }

    /**
     * 恢复回收站链接
     * @param requireParam 恢复回收站链接请求参数
     */
    @PostMapping("/api/short-link/v1/recycle-bin/recover")
    public Result<Void> restoreRecycleBinLink(@RequestBody RecycleBinRestoreReqDTO requireParam){
        recycleBinService.restoreRecycleBinLink(requireParam);
        return Results.success();
    }

    /**
     * 移除回收站链接
     * @param requireParam 移除回收站链接请求参数
     */
    @PostMapping("/api/short-link/v1/recycle-bin/remove")
    public Result<Void> removeRecycleBinLink(@RequestBody RecycleBinRemoveReqDTO requireParam){
        recycleBinService.removeRecycleBinLink(requireParam);
        return Results.success();
    }
}
